package learn.Thread;

import java.util.concurrent.CountDownLatch;

/*
* Question A：有100个任务需要分成10批执行，每批执行有顺序（即第一批执行完执行第二批）。
● 说明：10批任务有序执行，每批任务的10个任务要做到并发执行
● 加分项：如果可以，写出多种不同原理或不同工具的实现方式
* */
public class test16 {
    public static void main(String[] args) throws InterruptedException {
        for (int i = 1; i < 11; i++) {
            CountDownLatch count = new CountDownLatch(10);
            for (int j = 0; j < 10; j++) {
                Thread star = new star(count, i);
                star.start();
            }
            count.await();
        }
    }

}

class star extends Thread{
    private CountDownLatch count;
    private int flag;

    public star(CountDownLatch count,int flag){
        this.count = count;
        this.flag = flag;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"正在执行第"+flag+"批次的任务");
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        count.countDown();
    }
}